import { Injectable } from '@angular/core';

@Injectable()
export class ScrollService {
  constructor ( ) {}

  tabIndex (e, el, el1, el2 = undefined, el3 = undefined, el4 = undefined, el5 = undefined) {
    let parentTop = el.getBoundingClientRect().top
    let el1Top = el1 && el1.getBoundingClientRect().top - parentTop
    let el2Top = el2 && el2.getBoundingClientRect().top - parentTop
    let el3Top = el3 && el3.getBoundingClientRect().top - parentTop
    let el4Top = el4 && el4.getBoundingClientRect().top - parentTop
    let el5Top = el5 && el5.getBoundingClientRect().top - parentTop
    if (el1Top !== undefined) {
      if (el1Top === 0) {
        return 0
      }
    }
    if (el2Top !== undefined) {
      if (el1Top < 0 && el2Top > 0) {
        return 0
      }
    } else {
      return 0
    }
    if (el3Top !== undefined) {
      if (el2Top <= 0 && el3Top > 0) {
        return 1
      }
    } else {
      return 1
    }
    if (el4Top !== undefined) {
      if (el3Top <= 0 && el4Top > 0) {
        return 2
      }
    } else {
      return 2
    }
    if (el5Top !== undefined) {
      if (el4Top <= 0 && el5Top > 0) {
        return 3
      } else {
        return 4
      }
    } else {
      return 3
    } 
  }
}